/**author-szy
 * 科室费用分类分析
 */
$(function(){

    showCondition(true, 1, 1, 1, []);

    var barColor = ["#f07043","#50a1d4","#7bd9a5","#d0648a","#f58db2","#f2b3c9"];

    //全院总体指标
    var totalQuota = [
        ['InCaseCnt', '入组病例数'],
        ['CMI', 'CMI值'],
        ['AvgDays', '平均住院日'],
        ['AvgFee', '次均费用'],
        ['AvgDrugFee', '次均药品费(元)'],
        ['AvgMateFee', '次均耗材费(元)'],
        ['DrugRatio', '药品费用占比(%)'],
        ['MaterialRatio', '耗材费占比(%)']
    ];

    //消耗指数指标
    var effQuota = [
        ['TimeEff', '时间消耗指数'],
        ['FeeEff', '费用消耗指数'],
        ['MedFeeEff', '医疗费用消耗指数'],
        ['TechFeeEff', '医技费用消耗指数'],
        ['NursFeeEff', '护理费用消耗指数'],
        ['DrugMaterFeeEff', '药品耗材费用消耗指数'],
        ['ManageFeeEff', '管理费用消耗指数']
    ];

    //五大类费用指标
    var feeQuota = [
        ['MedFee', '医疗类费用'],
        ['TechFee', '医技类费用'],
        ['NursFee', '护理类费用'],
        ['DrugMaterFee', '药品耗材类费用'],
        ['ManageFee', '管理类费用']
    ];

    //当前科室
    var param = jQuery.extend(true,{},paramTabPage[tabId]);
    var depCode=param.pardepCode; //科室编码
    var clinicCode=param.pargroupName; //主诊组编码
    var clinicName=param.clinic_desc;   //主诊组描述
    var dateFrom=param.dateFrom; //开始日期
    var dateTo=param.dateTo;   	 //截止日期
    var hospCode=param.hospCode; //院区编码
    var monitorType=param.monitorType;

    //整体情况标题栏填写
    $("#"+tabId+" #feeDep_header").html(clinicName);
    $("#"+tabId+" #depFeeTitleAll").html("整体情况——"+clinicName);

    //科室费用构成及对比
    depFeeFormAndCompare();
    //费用变化趋势
    depFeeVareTrend();

    //不同特征区间内病例分布情况
    var sliderValBench_A = 20  ; //标杆法超标系数
    var sliderValBench_B = 0.5  ;  //标差法超标系数

    var compareObj='AvgDays';  //病例分析模板比较对象

    var compareRange='1';   //compareRange: 1是超标N%及以上病例  2是超标N%以内病例

    //滑动块停止加载
    $("#"+tabId+" #benchmarkSlider1_clinic").ionRangeSlider({
        min: 0,
        max: 99,
        step: 1,
        postfix: '%',
        grid: true,
        onFinish: function(){
            depOverFeeCaseShow(sliderValBench_A,compareObj,"1",compareRange);
        }
    });
    $("#"+tabId+" #benchmarkSlider2_clinic").ionRangeSlider({
        min: 0,
        max: 5,
        step: 0.1,
        grid: true,
        onFinish: function(){
            depOverFeeCaseShow(sliderValBench_B,compareObj,"2",compareRange);
        }
    });

    //倒数第三个参数 ： 1是标杆法  2是标差法
    depOverFeeCaseShow(sliderValBench_A,compareObj,"1",compareRange);
    depOverFeeCaseShow(sliderValBench_B,compareObj,"2",compareRange);

    //病例分布查询条件条件变更
    $("#"+tabId+" #clinicFeeCompareObj").change(function(){
        compareObj=$('#'+tabId+' #clinicFeeCompareObj').val();
        depOverFeeCaseShow(sliderValBench_A,compareObj,"1",compareRange);
        depOverFeeCaseShow(sliderValBench_B,compareObj,"2",compareRange);
    });

    //特异病例范围表格复选框(标杆法)
    $('#'+tabId+' input[name="szyClinicFeeOutAbnormalCB_A"]').click(function(){
        $(this).attr("checked",true);//设置当前选中checkbox的状态为checked
        $(this).siblings().attr("checked",false); //设置当前选中的checkbox同级(兄弟级)其他checkbox状态为未选中
        compareRange=$('input[name="szyClinicFeeOutAbnormalCB_A"]:checked').val();
        //超标的比例值
        var sliderValBenchLater;
        sliderValBenchLater=1+sliderValBench_A/100;
        //排除特异病例后次均费用.费用构成及其对比情况表
        loadDepFeeOutAbnormalTable(sliderValBench_A,compareObj,'1',compareRange,sliderValBenchLater);
    });

    //特异病例范围表格复选框(标差法)
    $('#'+tabId+' input[name="szyClinicFeeOutAbnormalCB_B"]').click(function(){
        $(this).attr("checked",true);//设置当前选中checkbox的状态为checked
        $(this).siblings().attr("checked",false); //设置当前选中的checkbox同级(兄弟级)其他checkbox状态为未选中
        compareRange=$('input[name="szyClinicFeeOutAbnormalCB_B"]:checked').val();
        //排除特异病例后次均费用.费用构成及其对比情况表
        loadDepFeeOutAbnormalTable(sliderValBench_B,compareObj,'2',compareRange,sliderValBench_B);
    });

    //获取主诊组整体情况（第一个模块的内容）
    var quotaCodes = totalQuota.map(function(v){return v[0]}).join(',')+','
        + effQuota.map(function(v){return v[0]}).join(',')+','
        + feeQuota.map(function(v){return v[0]}).join(',')
        + ',TotalFee,TotalCaseCnt';

    //动态拼接echars的ID
    var str = '';
    str +='<div class="height300" id="'+clinicCode+'_clinicFee_effChart'+depCode+'"> </div>';
    $("#"+tabId+" #clinicFee_effChart_ci").html(str);
    var strA= '';
    strA +='<div id="'+clinicCode+'_clinicFee_feeChart'+depCode+'" class="height300"></div>';
    $("#"+tabId+" #clinicFee_feeChart_ci").html(strA);

    getQuotaValue(quotaCodes,function(result){
        result = result[0];
        totalCaseCnt = result.TotalCaseCnt;
        var totalQuotaHtml = '';
        for (var q=0 ; q< totalQuota.length; q++) {
            totalQuotaHtml += '<td><p class="value">'+formatNumber(result[totalQuota[q][0]],2)+'</p><p class="title">'+totalQuota[q][1]+'</p></td>';
        }
        $('#'+tabId+' #feeClinicTable tr').html(totalQuotaHtml);

        //消耗指数监测
        var effOption = {
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data:['指数值']
            },
            color: barColor,
            xAxis: {
                type: 'category',
                data: effQuota.map(function(v){return v[1]})
            },
            yAxis: {
                type: 'value'
            },
            series: [{
                name: '指数值',
                data: effQuota.map(function(v){return result[v[0]]}),
                type: 'bar'
            }]
        };
        var effChart = echarts.init(document.getElementById(clinicCode+'_clinicFee_effChart'+depCode));
        effChart.setOption(effOption);

        //费用构成对比图
        var feeOption = {
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data:['本期值','标杆值']
            },
            color: barColor,
            xAxis: {
                type: 'category',
                data: feeQuota.map(function(v){return v[1]})
            },
            yAxis: {
                name: '费用占比（%）',
                type: 'value'
            },
            series: [{
                name: '本期值',
                data: feeQuota.map(function(v){return feeRatio(result, v[0])}),
                type: 'bar',
                markPoint: {
                    data: [
                        {type: 'max', name: '最大值'},
                        {type: 'min', name: '最小值'}
                    ]
                }
            },{
                name: '标杆值',
                data: feeQuota.map(function(v){return feeRatio(result, v[0], 'cc')}),
                type: 'bar',
                markPoint: {
                    data: [
                        {type: 'max', name: '最大值'},
                        {type: 'min', name: '最小值'}
                    ]
                }
            }]
        };
        var feeChart = echarts.init(document.getElementById(clinicCode+'_clinicFee_feeChart'+depCode));
        feeChart.setOption(feeOption);
    });
});

//科室费用构成及对比
//本期：year  标杆std  上期month  同期 year cc manage绩效值
function  depFeeFormAndCompare(){

    var param = jQuery.extend(true,{},paramTabPage[tabId]);
    var depCode=param.pardepCode;

    var depAvgFeeEch = {"id":"depAvgFeeEch","title":"次均费用",
        "quotas":  [ {"code":"TotalCaseCnt","title":"病例数"}
            ,{"code":"AvgFee","title":"次均费用(元)"}
            ,{"code":"AvgDays","title":"平均住院日"}
            ,{"code":"AvgDrugFee","title":"次均药品费(元)"}
            ,{"code":"DrugRatio","title":"药品费用(%)"}
            ,{"code":"AvgMateFee","title":"次均耗材费(元)"}
            ,{"code":"MaterialRatio","title":"耗材费占比(%)"}
            ,{"code":"TechFee","title":"医技费"}
            ,{"code":"ManageFee","title":"管理费"}
            ,{"code":"MedFee","title":"医疗费"}
            ,{"code":"NursFee","title":"护理费"}
            ,{"code":"DrugMaterFee","title":"药品费"}],"data":{}} ;

    var depAvgFeeEchManage = {"id":"depAvgFeeEch","title":"次均费用",
        "quotas":  [ {"code":"AvgFee","title":"次均费用(元)"}
            ,{"code":"AvgDays","title":"平均住院日"}
            ,{"code":"AvgDrugFee","title":"次均药品费(元)"}
            ,{"code":"DrugRatio","title":"药品费用(%)"}
            ,{"code":"AvgMateFee","title":"次均耗材费(元)"}
            ,{"code":"MaterialRatio","title":"耗材费占比(%)"}],"data":{}} ;

    var compareType = ["year","std","month","manage"] ;
    for(var o in compareType) {
        var param = jQuery.extend(true,{},paramTabPage[tabId]);
        var paramNew= JSON.parse(JSON.stringify(param));
        paramNew.compareType = compareType[o];
        paramNew.monitorType ="clinic";
        // 当比较值为标杆时，仅获取标杆值，不获取本期值
        if(compareType[o] == "std") {
            paramNew.msCode = "std_computer" ;
        }else if(compareType[o] == "manage"){
            paramNew.msCode = "manager_inner" ;
            paramNew.monitorType = "dep"; //主诊组的绩效值用当前科室的
        }
        paramNew.isGetCc = "1" ;
        loadDepFeeDataSzy(depAvgFeeEch,depAvgFeeEchManage,function(){
            // 当不同比较类型的数据均返回的时候
            if(depAvgFeeEch.data.year && depAvgFeeEch.data.std && depAvgFeeEch.data.month&& depAvgFeeEch.data.manage) {
                // 当数据均返回的时候开始拼装数据
                var data = depAvgFeeEch.data ;
                // 求次均五大类费用
                var compareTypeNo = ["year","std","month","manage"] ;
                for(var i in compareTypeNo) {
                    if(data[compareTypeNo[i]][0]) {
                        //次均五大类费用
                        data[compareTypeNo[i]][0].TechFee = (data[compareTypeNo[i]][0].TechFee/data[compareTypeNo[i]][0].TotalCaseCnt).toFixed(2) ;
                        data[compareTypeNo[i]][0].ManageFee = (data[compareTypeNo[i]][0].ManageFee/data[compareTypeNo[i]][0].TotalCaseCnt).toFixed(2) ;
                        data[compareTypeNo[i]][0].MedFee = (data[compareTypeNo[i]][0].MedFee/data[compareTypeNo[i]][0].TotalCaseCnt).toFixed(2) ;
                        data[compareTypeNo[i]][0].NursFee = (data[compareTypeNo[i]][0].NursFee/data[compareTypeNo[i]][0].TotalCaseCnt).toFixed(2) ;
                        data[compareTypeNo[i]][0].DrugMaterFee = (data[compareTypeNo[i]][0].DrugMaterFee/data[compareTypeNo[i]][0].TotalCaseCnt).toFixed(2) ;
                        if(compareTypeNo[i]=="year"||compareTypeNo[i]=="month"){
                            data[compareTypeNo[i]][0].TechFeecc = (data[compareTypeNo[i]][0].TechFeecc/data[compareTypeNo[i]][0].TotalCaseCntcc).toFixed(2) ;
                            data[compareTypeNo[i]][0].ManageFeecc = (data[compareTypeNo[i]][0].ManageFeecc/data[compareTypeNo[i]][0].TotalCaseCntcc).toFixed(2) ;
                            data[compareTypeNo[i]][0].MedFeecc = (data[compareTypeNo[i]][0].MedFeecc/data[compareTypeNo[i]][0].TotalCaseCntcc).toFixed(2) ;
                            data[compareTypeNo[i]][0].NursFeecc = (data[compareTypeNo[i]][0].NursFeecc/data[compareTypeNo[i]][0].TotalCaseCntcc).toFixed(2) ;
                            data[compareTypeNo[i]][0].DrugMaterFeecc = (data[compareTypeNo[i]][0].DrugMaterFeecc/data[compareTypeNo[i]][0].TotalCaseCntcc).toFixed(2) ;
                        }else if(compareTypeNo[i]=="std"){
                            data[compareTypeNo[i]][0].TechFeecc = (data[compareTypeNo[i]][0].TechFeecc/data[compareTypeNo[i]][0].TotalCaseCnt).toFixed(2) ;
                            data[compareTypeNo[i]][0].ManageFeecc = (data[compareTypeNo[i]][0].ManageFeecc/data[compareTypeNo[i]][0].TotalCaseCnt).toFixed(2) ;
                            data[compareTypeNo[i]][0].MedFeecc = (data[compareTypeNo[i]][0].MedFeecc/data[compareTypeNo[i]][0].TotalCaseCnt).toFixed(2) ;
                            data[compareTypeNo[i]][0].NursFeecc = (data[compareTypeNo[i]][0].NursFeecc/data[compareTypeNo[i]][0].TotalCaseCnt).toFixed(2) ;
                            data[compareTypeNo[i]][0].DrugMaterFeecc = (data[compareTypeNo[i]][0].DrugMaterFeecc/data[compareTypeNo[i]][0].TotalCaseCnt).toFixed(2) ;
                        }
                    }
                }
                //科室次均费用对比图及科室费用构成及其对比图加载
                loadDepFeeFormEchars(data);
                //加载次均费用、费用构成及其对比情况表
                loadClinicAvgFeeCompareTable(data,depAvgFeeEch);
            }
        },paramNew) ;
    }
}
/**
 * 加载次均费用、费用构成及其对比情况表
 * @param data
 */
function loadClinicAvgFeeCompareTable(data,depAvgFeeEch){
    var param = jQuery.extend(true,{},paramTabPage[tabId]);
    var clinicCode=param.pargroupName; //主诊组编码
    var clinicName=param.clinic_desc;   //主诊组描述
    //填充columns
    var columns=[
        {"data": "desc","title":"指标项"},
        {"data": "TotalCaseCnt","title":"病例数",
            "render": function(obj, type, full) {
                if(full.desc == "标杆值"||full.desc == "绩效值") {
                    return "——" ;
                }
                return formatNumber(full.TotalCaseCnt,0) ;
            }
        },
        {"data": "AvgFee","title":"次均费用",
            "render": function(obj, type, full) {
                if(full.desc == "标杆值"||full.desc == "绩效值") {
                    if(full.AvgFee==null||full.AvgFee==""||full.AvgFee==undefined||full.AvgFee=="0"||full.AvgFee==0){
                        return "——" ;
                    }else{
                        return formatNumber(full.AvgFee,2) ;
                    }
                }else{
                    return formatNumber(full.AvgFee,2) ;
                }
            }
        },
        {"data": "AvgDays","title":"平均住院日",
            "render": function(obj, type, full) {
                if(full.desc == "标杆值"||full.desc == "绩效值") {
                    if(full.AvgDays==null||full.AvgDays==""||full.AvgDays==undefined||full.AvgDays=="0"||full.AvgDays==0){
                        return "——" ;
                    }else{
                        return formatNumber(full.AvgDays,2) ;
                    }
                }else{
                    return formatNumber(full.AvgDays,2) ;
                }
            }
        },
        {"data": "AvgDrugFee","title":"次均药品费",
            "render": function(obj, type, full) {
                if(full.desc == "标杆值"||full.desc == "绩效值") {
                    if(full.AvgDrugFee==null||full.AvgDrugFee==""||full.AvgDrugFee==undefined||full.AvgDrugFee=="0"||full.AvgDrugFee==0){
                        return "——" ;
                    }else{
                        return formatNumber(full.AvgDrugFee,2) ;
                    }
                }else{
                    return formatNumber(full.AvgDrugFee,2) ;
                }
            }
        },
        {"data": "DrugRatio","title":"药品费占比(%)",
            "render": function(obj, type, full) {
                if(full.desc == "标杆值"||full.desc == "绩效值") {
                    if(full.DrugRatio==null||full.DrugRatio==""||full.DrugRatio==undefined||full.DrugRatio=="0"||full.DrugRatio==0){
                        return "——" ;
                    }else{
                        return formatNumber(full.DrugRatio,2) ;
                    }
                }else{
                    return formatNumber(full.DrugRatio,2) ;
                }
            }
        },
        {"data": "AvgMateFee","title":"次均耗材费",
            "render": function(obj, type, full) {
                if(full.desc == "标杆值"||full.desc == "绩效值") {
                    if(full.AvgDrugFee==null||full.AvgDrugFee==""||full.AvgDrugFee==undefined||full.AvgDrugFee=="0"||full.AvgDrugFee==0){
                        return "——" ;
                    }else{
                        return formatNumber(full.AvgDrugFee,2) ;
                    }
                }else{
                    return formatNumber(full.AvgDrugFee,2) ;
                }
            }
        },
        {"data": "MaterialRatio","title":"耗材费占比(%)",
            "render": function(obj, type, full) {
                if(full.desc == "标杆值"||full.desc == "绩效值") {
                    if(full.MaterialRatio==null||full.MaterialRatio==""||full.MaterialRatio==undefined||full.MaterialRatio=="0"||full.MaterialRatio==0){
                        return "——" ;
                    }else{
                        return formatNumber(full.MaterialRatio,2) ;
                    }
                }else{
                    return formatNumber(full.MaterialRatio,2) ;
                }
            }
        },
        {"data": "MedFee","title":"次均医疗费(元)",
            "render": function(obj, type, full) {
                if(full.desc == "绩效值") {
                    return "——" ;
                }else{
                    return formatNumber(full.MedFee,2) ;
                }
            }
        },
        {"data": "NursFee","title":"次均护理费(元)",
            "render": function(obj, type, full) {
                if(full.desc == "绩效值") {
                    return "——" ;
                }else{
                    return formatNumber(full.NursFee,2) ;
                }
            }
        },
        {"data": "ManageFee","title":"次均管理费(元)",
            "render": function(obj, type, full) {
                if(full.desc == "绩效值") {
                    return "——" ;
                }else{
                    return formatNumber(full.ManageFee,2) ;
                }
            }
        },
        {"data": "TechFee","title":"次均医技费(元)",
            "render": function(obj, type, full) {
                if(full.desc == "绩效值") {
                    return "——" ;
                }else{
                    return formatNumber(full.TechFee,2) ;
                }
            }
        },
        {"data": "DrugMaterFee","title":"次均药耗费(元)",
            "render": function(obj, type, full) {
                if(full.desc == "绩效值") {
                    return "——" ;
                }else{
                    return formatNumber(full.DrugMaterFee,2) ;
                }
            }
        } ,
        {"data": "operation","title":"操作",
            "render": function(obj, type, full,meta) {
                var rowData = JSON.stringify(full).replace(/"/g,'&quot;');
                var stdData = JSON.stringify(data.std[0]).replace(/"/g,'&quot;');
                var str = "";
                if(meta.row==0) {
                    str = '<a class="costStructure" href="javascript:feeStrucClinic(\''+rowData+'\',\''+stdData+'\')">费用构成</a>&nbsp;<a class="drgSZY" href="javascript:loadDRGPage(\''+clinicName+'\',\''+clinicCode+'\')">病组</a>';
                } else if(meta.row==1){
                } else{
                    str = '<a class="costStructure" href="javascript:feeStrucClinic(\''+rowData+'\',\''+stdData+'\')">费用构成</a>';
                }
                return str;
            }
        }
    ];
    //填充数据
    var dataTab = [] ;
    for(var i = 0 ; i<5 ; i++) {
        var value = {} ;
        for(var o in columns) {
            // 指标编码
            var quotaCode = columns[o].data ;
            if(o == 0){
                switch(i) {
                    case  0 : value[quotaCode] = "本期值" ; break ;
                    case  1 : value[quotaCode] = "绩效值" ; break ;
                    case  2 : value[quotaCode] = "标杆值" ; break ;
                    case  3 : value[quotaCode] = "上期值" ; break ;
                    case  4 : value[quotaCode] = "同期值" ; break ;
                }
            } else {
                switch(i) {
                    case  0 : value[quotaCode] = findQuotasVal(data,"year",quotaCode) ; break ;
                    case  1 : value[quotaCode] = findQuotasVal(data,"manage",quotaCode+"cc") ; break ;
                    case  2 : value[quotaCode] = findQuotasVal(data,"std",quotaCode+"cc") ; break ;
                    case  3 : value[quotaCode] = findQuotasVal(data,"month",quotaCode+"cc") ; break ;
                    case  4 : value[quotaCode] = findQuotasVal(data,"year",quotaCode+"cc") ; break ;
                }
            }
        }
        dataTab.push(value) ;
    }
    var depName = data.year[0] == undefined ? "" : data.year[0].ddesc ;
    var depCode = data.year[0] == undefined ? "" : data.year[0].ccode ;
    var paramsDataTables={searching:false,lengthChange:false,ordering:false,stateSave:true,info:false,paging:false,tableTitle:depName+"次均费用、费用构成及其对比情况表",columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
    var table = $("#"+tabId+" #clinicAvgFeeCompareTable").dataTableBasic(columns,dataTab,paramsDataTables) ;

    //超标颜色变红
    for(var c = 4;c<=14;c++)
    {//从第4列 到第12列 (开始为1)
        for(var r=1;r<=5;r++)
        {//从第1行 到第4行 (开始为1)
            if(r==2||r==3)
            {
                continue;//绩效行和标杆行
            }
            var cv = $("#"+tabId+" #clinicAvgFeeCompareTable tr:nth-child("+r+") td:nth-child("+c+")").text();//列值
            var tv = $("#"+tabId+" #clinicAvgFeeCompareTable tr:nth-child("+3+") td:nth-child("+c+")").text();//标杆值
            if(transformFloat(cv)>transformFloat(tv))
            {
                $("#"+tabId+" #clinicAvgFeeCompareTable tr:nth-child("+r+") td:nth-child("+c+")").css("color","red");
            }
        }
    }
}

/**
 * 科室次均费用对比图及科室费用构成及其对比图加载
 */
function loadDepFeeFormEchars(data){

    var y = ["同期值","上期值","标杆值","本期值"] ;
    var barColor = ["#f07043","#50a1d4","#7bd9a5","#d0648a","#f58db2","#f2b3c9"];

    //次均费用的值
    var techFee = [findQuotasVal(data,"year","TechFeecc"),findQuotasVal(data,"month","TechFeecc"),findQuotasVal(data,"std","TechFeecc"),findQuotasVal(data,"year","TechFee")] ;
    var manageFee = [findQuotasVal(data,"year","ManageFeecc"),findQuotasVal(data,"month","ManageFeecc"),findQuotasVal(data,"std","ManageFeecc"),findQuotasVal(data,"year","ManageFee")] ;
    var medFee = [findQuotasVal(data,"year","MedFeecc"),findQuotasVal(data,"month","MedFeecc"),findQuotasVal(data,"std","MedFeecc"),findQuotasVal(data,"year","MedFee")] ;
    var nursFee =[findQuotasVal(data,"year","NursFeecc"),findQuotasVal(data,"month","NursFeecc"),findQuotasVal(data,"std","NursFeecc"),findQuotasVal(data,"year","NursFee")] ;
    var drugMaterFee = [findQuotasVal(data,"year","DrugMaterFeecc"),findQuotasVal(data,"month","DrugMaterFeecc"),findQuotasVal(data,"std","DrugMaterFeecc"),findQuotasVal(data,"year","DrugMaterFee")] ;

    //次均费用五大类总和
    var totalFiveFee=[ calcuteTotalFee(data,"yearcc"),calcuteTotalFee(data,"month"),
        calcuteTotalFee(data,"std"),calcuteTotalFee(data,"year")];


    //科室次均费用对比图
    var textStyle={"fontSize":10};
    var legendDep = {"x":50,"y":10,"height":40,"top":20,"data": ["次均费用", "次均医疗费", "次均护理费","次均管理费","次均医技费","次均药耗费"] } ;
    var paramDep = {"title":data.year[0].ddesc+"次均费用对比图","legend":legendDep, "color": barColor,
        "series":[
            {"name":"次均费用","type":"bar","data":totalFiveFee},
            {"name":"次均医疗费","type":"bar","data":medFee,"barWidth":13,"stack": "次均费用"},
            {"name":"次均护理费","type":"bar","data":nursFee,"barWidth":13,"stack": "次均费用"},
            {"name":"次均管理费","type":"bar","data":manageFee,"barWidth":13,"stack": "次均费用"},
            {"name":"次均医技费","type":"bar","data":techFee,"barWidth":13,"stack": "次均费用"},
            {"name":"次均药耗费","type":"bar","data":drugMaterFee,"barWidth":13,"stack": "次均费用"}
        ],"yAxis":{ "heigth":35 ,"data":y, "type" : "category"}};
    paramDep.gridTop = 90 ;
    drawDepAvgFeeBarChart("clinicAvgFeeCompareEchars",paramDep);

    // 图例位置
    var legend = {"x":50,"y":20, "data": ["次均医疗费", "次均护理费","次均管理费","次均医技费","次均药耗费"] } ;
    var seriesData = [
        {"name":"次均医疗费","type":"bar","data":medFee},
        {"name":"次均护理费","type":"bar","data":nursFee},
        {"name":"次均管理费","type":"bar","data":manageFee},
        {"name":"次均医技费","type":"bar","data":techFee},
        {"name":"次均药耗费","type":"bar","data":drugMaterFee}
    ];
    //添加bar图对齐的补偿图
    var placeHoledStyle = {
        normal:{
            barBorderColor:'rgba(0,0,0,0)',
            color:'rgba(0,0,0,0)'
        },
        emphasis:{
            barBorderColor:'rgba(0,0,0,0)',
            color:'rgba(0,0,0,0)'
        }
    };
    var tooltip = {
        trigger: 'axis',
        axisPointer : {
            type : 'shadow'
        },
        formatter : '{b}<br/>{a0}:{c0}<br/>{a2}:{c2}<br/>{a4}:{c4}<br/>{a6}:{c6}<br/>{a8}:{c8}'
    };
    for (var i = 0; i < seriesData.length; i++) {
        var thisData = seriesData[i];
        seriesData.splice(i+1, 0 ,{
            name: thisData.name,
            type: thisData.type,
            itemStyle: placeHoledStyle,
            data: thisData.data.map(function(v){return Math.max.apply(null,thisData.data.map(function(v){return isNaN(v)?0:v}))-v+50})
        });
        i++;
    }
    var param = {"title":data.year[0].ddesc+"费用构成及其对比图",tooltip: tooltip,"legend":legend,"color": barColor, "series":seriesData,"y":{"data":y}};
    // 网格上边距
    param.gridTop = 80 ;
    // 病组费用构成
    drawDepAnaFeeBarChart("clinicFeeFormEchars",param,null,"stackbar") ;
}

//费用变化趋势
function depFeeVareTrend(){
    var param = jQuery.extend(true,{},paramTabPage[tabId]);
    var depCode=param.pardepCode;
    var depName=param.depDesc;
    var dateFrom=param.dateFrom;
    var dateTo=param.dateTo;
    var hospCode=param.hospCode;
    var monitorType=param.monitorType;
    var groupCode=param.pargroupName; //主诊组编码
    var pType=param.pType; //人员类型 0是全体 1是医保
    $.post(contextPath + "/feeAnalysisDep/getDepFeeVareTrend.dhc", {
        "dateFrom":dateFrom,
        "dateTo": dateTo,
        "depCode": depCode,
        "hospCode": hospCode,
        "pType":pType,
        "groupCode":groupCode
    }).done(function(res){
        var data=res.data;
        //加载费用变化趋势图
        loadDepFeeVareTrendEchars(data);
    });
}
//加载费用变化趋势图
function loadDepFeeVareTrendEchars(data){

    var param = jQuery.extend(true,{},paramTabPage[tabId]);
    var depName=param.clinic_desc;
    var dateFrom=param.dateFrom; //开始日期
    var dateTo=param.dateTo;   	 //截止日期
    var dateFromStr=[]; dateToStr=[];
    dateFromStr=dateFrom.split("-");
    dateToStr=dateTo.split("-");
    //计算dateFrom与dateTo之间的月份差值
    //var month=Number(dateToStr[1])+Number((dateToStr[0]-dateFromStr[0])*12)+1-Number(dateFromStr[1]);
    var month = data.length;

    //x日期段坐标轴
    var x=[] ;
    var medFee=[];
    var techFee=[];
    var nursFee=[];
    var drugMaterFee=[];
    var manageFee=[];
    for(var o in data){
        x.push(data[o].MONTHS);
        medFee.push(data[o].MEDFEE);
        techFee.push(data[o].TECHFEE);
        nursFee.push(data[o].NURSFEE);
        drugMaterFee.push(data[o].DRUGMATERFEE);
        manageFee.push(data[o].MANAGEFEE);
    }
    var barColor = ["#f07043","#50a1d4","#7bd9a5","#d0648a","#f58db2","#f2b3c9"];
    var legend = {"x":50,"y":5,"height":40,"top":20,"data": ["次均医疗费","次均医技费", "次均护理费","次均药耗费","次均管理费"] } ;
    var param =  {"title":depName+"费用变化趋势图","legend":legend,"color": barColor,
        "series":[
            {"name":"次均医疗费","type":"line", "stack":"总量","data":medFee},
            {"name":"次均医技费","type":"line", "stack":"总量","data":techFee},
            {"name":"次均护理费","type":"line", "stack":"总量","data":nursFee},
            {"name":"次均药耗费","type":"line", "stack":"总量","data":drugMaterFee},
            {"name":"次均管理费","type":"line", "stack":"总量","data":manageFee}
        ],"xAxis":{"data":x ,"type" : "category","boundaryGap":"false"}};
    param.gridTop = 80 ;
    drawDepFeeVareTrendChart("clinicFeeVareTrendEchars",param);

    //科室费用构成及其对比图
    var xAxisData = ['次均医疗费','次均医技费','次均护理费','次均药耗费','次均管理费'] ; //x坐标轴
    var xAxisQuota=['MEDFEE','TECHFEE','NURSFEE','DRUGMATERFEE','MANAGEFEE'] ;//取值quota

    var customData = [];
    var legendData = []; //图例的月份值
    var dataList = [];

    legendData.push('trend');
    var encodeY = [];
    for (var i = 0; i < data.length; i++) {
        legendData.push(data[i].MONTHS);
        dataList.push([]);
        encodeY.push(1 + i);
    }

    for (var i = 0; i < xAxisQuota.length; i++) {
        var customVal = [i];
        customData.push(customVal);
        for (var j = 0; j < dataList.length; j++) {
            var value=data[j][xAxisQuota[i]];
            dataList[j].push(value);
            customVal.push(value); //趋势图的折线
        }
    }

    function renderItem(params, api) {
        var xValue = api.value(0);
        var currentSeriesIndices = api.currentSeriesIndices();
        var barLayout = api.barLayout({
            barGap: '30%', barCategoryGap: '20%', count: currentSeriesIndices.length - 1
        });

        var points = [];
        for (var i = 0; i < currentSeriesIndices.length; i++) {
            var seriesIndex = currentSeriesIndices[i];
            if (seriesIndex !== params.seriesIndex) {
                var point = api.coord([xValue, api.value(seriesIndex)]);
                point[0] += barLayout[i - 1].offsetCenter;
                point[1] -= 20;
                points.push(point);
            }
        }
        var style = api.style({
            stroke: api.visual('color'),
            fill: null
        });

        return {
            type: 'polyline',
            shape: {
                points: points
            },
            style: style
        };
    }

    option = {
        title: {
            text: depName+"费用变化趋势图",
            subtext: "",
            padding: 2,
            top: 0 ,
            textStyle:{
                fontSize:15
            }
        },
        gridTop : 80,
        tooltip: {
            trigger: 'axis',
            formatter: function(params){
                var str='';
                params.forEach(function(a){
                    if(a.seriesIndex>0){
                        str+=a.seriesName+': '+a.value+'<br>'
                    }

                })
                return str;
            }

        },
        toolbox: {
            show: true,
            orient: 'vertical',
            left: 'right',
            top: '',
            feature: {
                saveAsImage: {}
            }
        },
        legend: {
            data: {}
        },
        xAxis: {
            data: xAxisData
        },
        yAxis: {},
        series: [{
            type: 'custom',
            name: 'trend',
            renderItem: renderItem,
            itemStyle: {
                normal: {
                    borderWidth: 2
                }
            },
            customStyle: {
                width: 0, // 线宽是0
                color: 'rgba(0, 0, 0, 0)' // 线的颜色是透明的
            },
            encode: {
                x: 0,
                y: encodeY
            },
            data: customData,
            z: 100
        }].concat(echarts.util.map(dataList, function (data, index) {
            return {
                type: 'bar',
                animation: false,
                name: legendData[index + 1],
                itemStyle: {
                    normal: {
                        opacity: 0.5
                    }
                },
                data: data
            };
        }))
    };
    drawDepFiveFeeVareTrendChart("clinicFiveFeeVareTrendEchars",option);
}

function loadDepFeeDataSzy(loadObj,loadObjManage,callback,params,relatedObj) {
    // 定义延迟对象
    var dtd = $.Deferred();
    // 构造查询指标code
    var quotas = [] ;
    //指标项（绩效值的不全）
    var loadQuo;
    if(params.compareType=="manage"){
        loadQuo=loadObjManage;
    }else{
        loadQuo=loadObj;
    }
    for(var o in loadQuo.quotas) {
        // 跳过页面计算指标
        if(loadQuo.quotas[o].code.indexOf("|") > 0) {
            continue ;
        }
        quotas.push(loadQuo.quotas[o].code) ;
    }
    var quotastr = quotas.join(",");
    var param=drgUI.setAjaxData(tabId);
    //json格式数据拷贝
    var paramNew= JSON.parse(JSON.stringify(param));

    // 设置默认值
    paramNew.quotaCode = quotastr ;
    // 根据传的参数修改默认值
    if(params && params.monitorType) {
        paramNew.monitorType = params.monitorType ;
    }
    if(params && params.mdcCode) {
        paramNew.parmdcCode = params.mdcCode ;
    }
    if(params && params.pardrgCode) {
        paramNew.pardrgCode = params.pardrgCode ;
    }
    if(params && params.depCode) {
        paramNew.pardepCode = params.pardepCode ;
    }
    if(params && params.compareType) {
        paramNew.compareType = params.compareType ;
    }
    if(params && params.isGetCc) {
        paramNew.isGetCc = params.isGetCc ;
    }
    if(params && params.msCode) {
        paramNew.msCode = params.msCode ;
    }
    if(params && params.isPayGroup) {
        paramNew.isPayGroup = params.isPayGroup ;
    }
    if(params && params.pType) {
        paramNew.pType = params.pType ;
    }
    if(params && params.pargroupName) {
        paramNew.pargroupName = params.pargroupName ;
    }
    $.post(contextPath + "/DrgsIndexCal/indexCal.dhc", paramNew ).done(function(data) {
        var data = data.data ;
        if(data.length>0){
            // 过滤病组数据
            loadObj.data[paramNew.compareType] = data ;
            if(callback && relatedObj) {
                callback(loadObj,relatedObj) ;
            } else if(callback) {
                callback(loadObj) ;
            }
        }
        // 将延迟对象改为完成状态
        dtd.resolve();
    });
    // 此时的dtd对象为 未完成状态
    return dtd.promise();
}

/**
 * 计算data的值
 * @param data
 * @param compareType
 * @param quotaCode
 * @returns
 */
function findQuotasVal(data,compareType,quotaCode) {
    if(data[compareType][0] && data[compareType][0][quotaCode]) {
        if(isNaN(data[compareType][0][quotaCode])){
            return data[compareType][0][quotaCode] ;
        } else {
            return Number(data[compareType][0][quotaCode]) ;
        }
    } else {
        return "" ;
    }
}
//主诊组维度
function findQuotasValRow(data,compareType,quotaCode,time) {
    if(data[time] && data[time][quotaCode]) {
        if(isNaN(data[time][quotaCode])){
            return data[time][quotaCode] ;
        } else {
            return Number(data[time][quotaCode]) ;
        }
    } else {
        return "" ;
    }
}
//计算次均
function calcuteTotalFee(data,quotaCode){
    if(quotaCode=="year"){
        return Number(data["year"][0]["TechFee"])+Number(data["year"][0]["ManageFee"])
            +Number(data["year"][0]["MedFee"])+Number(data["year"][0]["NursFee"])+Number(data["year"][0]["DrugMaterFee"]);
    }else if(quotaCode=="std"){
        return Number(data["std"][0]["TechFeecc"])+Number(data["std"][0]["ManageFeecc"])
            +Number(data["std"][0]["MedFeecc"])+Number(data["std"][0]["NursFeecc"])+Number(data["std"][0]["DrugMaterFeecc"]);
    }else if(quotaCode=="month"){
        return Number(data["month"][0]["TechFeecc"])+Number(data["month"][0]["ManageFeecc"])
            +Number(data["month"][0]["MedFeecc"])+Number(data["month"][0]["NursFeecc"])+Number(data["month"][0]["DrugMaterFeecc"]);
    }else if(quotaCode=="yearcc"){
        return Number(data["year"][0]["TechFeecc"])+Number(data["year"][0]["ManageFeecc"])
            +Number(data["year"][0]["MedFeecc"])+Number(data["year"][0]["NursFeecc"])+Number(data["year"][0]["DrugMaterFeecc"]);
    }
}
/**
 * 科室费用构成折线图数据
 */
function numberMultiplication(data){
    if(isNaN(data)){
        return data ;
    } else {
        return Number(data)*1.2 ;
    }
}

//不同特征区间内病例分布情况 compareType 1是标杆法  2是标差法
function depOverFeeCaseShow(sliderValBench,compareObj,compareType,compareRange){
    var param = jQuery.extend(true,{},paramTabPage[tabId]);
    var depCode=param.pardepCode;
    var depName=param.depDesc;
    var dateFrom=param.dateFrom;
    var dateTo=param.dateTo;
    var hospCode=param.hospCode;
    var pType=param.pType; //人员类型 0是全体 1是医保
    var groupCode=param.pargroupName; //主诊组编码
    var groupName=param.clinic_desc;

    //超标的比例值
    var sliderValBenchLater;
    //特异病例范围文字描述动态拼接
    var compareStr;
    var compareDesc_in;
    var compareDesc_more;
    if(compareType=="1"){
        sliderValBench = $('#'+tabId+' #benchmarkSlider1_clinic').val();
        sliderValBenchLater=1+sliderValBench/100;
        compareStr="A";
        compareDesc_in= "超标"+sliderValBench+"%及以上病例";
        compareDesc_more= "超标"+sliderValBench+"%以内病例";
    }else{
        sliderValBench = $('#'+tabId+' #benchmarkSlider2_clinic').val();
        sliderValBenchLater=sliderValBench;
        compareStr="B";
        compareDesc_in= "超出"+sliderValBench+"倍及以上标准差病例";
        compareDesc_more= "超出"+sliderValBench+"倍以内标准差病例";
    }

    $.post(contextPath + "/feeAnalysisDep/getDepOverFeeCaseShow.dhc", {
        "dateFrom":dateFrom,
        "dateTo": dateTo,
        "depCode": depCode,
        "hospCode": hospCode,
        "sliderValBench":sliderValBenchLater,
        "compareObj":compareObj,  //指标项
        "compareType" :compareType, //划分类型 1是标杆法区间划分 2是标差法区间划分
        "pType":pType,	//医保类型：0是全部 1是医保
        "groupCode":groupCode
    }).done(function(res){
        var data=res.data;
        //加载费用变化趋势图
        loadDepOverFeeCase(data,sliderValBench,groupName,compareType,compareObj,sliderValBenchLater);
    });

    $("#"+tabId+" .szyClinicFeeOutAbnormalA_"+compareStr).html(compareDesc_in);
    $("#"+tabId+" .szyClinicFeeOutAbnormalB_"+compareStr).html(compareDesc_more);

    //排除特异病例后次均费用.费用构成及其对比情况表
    loadDepFeeOutAbnormalTable(sliderValBench,compareObj,compareType,compareRange,sliderValBenchLater);

}

//加载不同特征区间内病例分布情况
function loadDepOverFeeCase(data,sliderValBench,groupName,compareType,compareObj,sliderValBenchLater){
    var param = jQuery.extend(true,{},paramTabPage[tabId]);
    var clinicCode=param.pargroupName; //主诊组编码
    var clinicName=param.clinic_desc;   //主诊组描述
    //不同特征区间内病例分布情况柱状图
    var x=[];
    if(compareType=="1"){
        x=["未超标病例","超标"+sliderValBench+"%以内病例","超标"+sliderValBench+"%及以上病例"];
    }else{
        x=["未超标病例","超出"+sliderValBench+"倍以内标准差病例","超出"+sliderValBench+"倍及以上标准差病例"];
    }
    var legendData=[]; //图例标题
    var sumCnt=[]; //各主诊组总数
    var series=[]; //series
    var notSum=0; inSum=0; moreSum=0;

    for(var o in data){
        legendData.push(data[o].DECC);
        notSum+=Number(data[o].NOTCNT);
        inSum+=Number(data[o].INCNT);
        moreSum+=Number(data[o].MORECNT);
    }
    var sumStrSeries;
    sumCnt=[notSum,inSum,moreSum];
    sumStrSeries={"name":"汇总","type":"bar","barWidth":20,"data":sumCnt};
    series.push(sumStrSeries);

    for(var o in data){
        var strSeries;
        var strSeriesObj=[];
        strSeriesObj.push(data[o].NOTCNT);
        strSeriesObj.push(data[o].INCNT);
        strSeriesObj.push(data[o].MORECNT);
        strSeries={"name":data[o].DECC,"type":"bar","data":strSeriesObj,"barWidth":20,"stack": "汇总"};
        series.push(strSeries);
    }

    var barColor = ["#f07043","#50a1d4","#7bd9a5","#d0648a","#f58db2","#f2b3c9"];
    var legend = {"x":50,"y":5,"height":40,"top":20,"data": legendData} ;
    var param =  {"title":groupName+"不同特征区间内病例主诊组分布图","legend":legend,"color": barColor,
        "series":series, "xAxis":{ heigth:50 ,"data":x , "type" : "category"} };
    param.gridTop = 100 ;

    //flag=0表示当前页签为标差法
    var flag=1;
    if(	$("#"+tabId+" #stdDeviation_clinicDep").hasClass("active")){
        flag=0;
        $("#"+tabId+" #benchmarking_clinicDep").addClass("active");
    }else{
        $("#"+tabId+" #stdDeviation_clinicDep").addClass("active");
    }

    var compareDesc_in;
    var compareDesc_more;
    if(compareType=="1"){
        compareDesc_in="超标"+sliderValBench+"%及以上病例";
        compareDesc_more="超标"+sliderValBench+"%以内病例";
    }else{
        compareDesc_in="超出"+sliderValBench+"倍以内标准差病例";
        compareDesc_more="超出"+sliderValBench+"倍及以上标准差病例";
    }
    //饼图
    var feeEchartData = [{
        name : '未超标病例',
        value : notSum
    },{
        name : compareDesc_in,
        value : inSum
    },{
        name : compareDesc_more,
        value : moreSum
    }];

    if(compareType=="1"){
        pieCharts($("#"+tabId+" #clinicCaseFeeCirclEchars_A"),feeEchartData ,"指标超标病例分布图",groupName);
    }else{
        pieCharts($("#"+tabId+" #clinicCaseFeeCirclEchars_B"),feeEchartData ,"指标超标病例分布图",groupName);
    }

    if(flag==0){
        $("#"+tabId+" #benchmarking_clinicDep").removeClass("active");
    }else{
        $("#"+tabId+" #stdDeviation_clinicDep").removeClass("active");
    }

    var allsum=notSum+inSum+moreSum;  //病例综合
    //填充columns
    var columns=[
        {"data": "DESC","title":"特征区间内病例类型"},
        {"data": "CNT","title":"病例数",
            "render": function(obj, type, full,meta) {
                if(full.CNT==0){
                    return 0 ;
                }else{
                    var abnomalType; //全部病例 all 未超标 not 超标N以内病例 in 超标N及以上病例 more
                    if(meta.row==0){
                        abnomalType="all";
                    }else if(meta.row==1){
                        abnomalType="not";
                    }else if(meta.row==2){
                        abnomalType="in";
                    }else {
                        abnomalType="more";
                    }
                    var dimensionType="dep_clinic";
                    return '<a href="javascript:loadFeeDepCase(\''+sliderValBenchLater+'\',\''+compareType+'\',\''+
                        compareObj+'\',\''+abnomalType+'\',\''+dimensionType+'\',\''+groupName+'\')">'+formatNumber(full.CNT,0)+'</a>';
                }
            }
        },
        {"data": "RATIO","title":"病例数占比（%）",
            "render": function(obj, type, full) {
                return formatNumber(full.CNT*100/full.ACNT,2) ;
            }
        },
        {"data": "OPER","title":"操作",
            "render": function(obj, type, full,meta) {
                var abnomalType; //全部病例 all 未超标 not 超标N以内病例 in 超标N及以上病例 more
                if(full.DESC.indexOf("全部病例")!=-1){
                    abnomalType="all";
                }else if(full.DESC.indexOf("未超标病例")!=-1){
                    abnomalType="not";
                }else if(full.DESC.indexOf("以内病例")!=-1){
                    abnomalType="in";
                }else {
                    abnomalType="more";
                }
                return '<a class="costStructure" href="javascript:loadDRGPageSimple(\''+full.DESC+'\',\''+full.CODE+'\',\''+sliderValBenchLater+'\',\''+compareType+'\',\''+compareObj+'\',\''+abnomalType+'\')">病组</a>';
            }
        }
    ];
    //填充数据
    var dataTab = [] ;
    var strA={"DESC":"全部病例","CNT":allsum,"ACNT":allsum};
    var strB={"DESC":"未超标病例","CNT":notSum,"ACNT":allsum};
    var depCaseFeeSzyTableId;
    if(compareType=="1"){
        depCaseFeeSzyTableId="clinicCaseFeeSzyTable_A";
        var strC={"DESC":"超标"+sliderValBench+"%以内病例","CNT":inSum,"ACNT":allsum};
        var strD={"DESC":"超标"+sliderValBench+"%及以上病例","CNT":moreSum,"ACNT":allsum};
    }else{
        depCaseFeeSzyTableId="clinicCaseFeeSzyTable_B";
        var strC={"DESC":"超标"+sliderValBench+"倍以内标准差病例","CNT":inSum,"ACNT":allsum};
        var strD={"DESC":"超标"+sliderValBench+"倍及以上标准差病例","CNT":moreSum,"ACNT":allsum};
    }
    dataTab.push(strA);
    dataTab.push(strB);
    dataTab.push(strC);
    dataTab.push(strD);
    var paramsDataTables={searching:false,lengthChange:false,ordering:false,stateSave:true,info:false,paging:false,tableTitle:"病例分布表",columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
    var table = $("#"+tabId+" #"+depCaseFeeSzyTableId).dataTableBasic(columns,dataTab,paramsDataTables) ;

}
/**
 * 排除特异病例后次均费用.费用构成及其对比情况表 (compareRange超标病例的范围)
 * @param data
 * @param sliderValBench
 */
function loadDepFeeOutAbnormalTable(sliderValBench,compareObj,compareType,compareRange,sliderValBenchLater){

    var param = jQuery.extend(true,{},paramTabPage[tabId]);
    var depCode=param.pardepCode;
    var dateFrom=param.dateFrom;
    var dateTo=param.dateTo;
    var hospCode=param.hospCode;
    var pType=param.pType; //人员类型 0是全体 1是医保
    var groupCode=param.pargroupName; //主诊组编码

    //排除特异病例后次均费用.费用构成及其对比情况表
    $.post(contextPath + "/feeAnalysisDep/getDepFeeOutAbnormalTable.dhc", {
        "dateFrom":dateFrom,
        "dateTo": dateTo,
        "depCode": depCode,
        "hospCode": hospCode,
        "sliderValBench":sliderValBenchLater,
        "compareObj":compareObj,  //指标项,如AvgDays 是平均住院日
        "compareType" :compareType, //划分类型 1是标杆法区间划分 2是标差法区间划分
        "compareAbnormal" : compareRange,  // 1是超标N%及以上病例  2是超标N%以内病例
        "pType" :pType,
        "groupCode":groupCode
    }).done(function(res){
        var data=res.data;
        //填充columns
        var columns=[
            {"data": "DECC","title":"指标项"},
            {"data": "TotalCaseCnt","title":"病例数",
                "render": function(obj, type, full) {
                    if(full.DECC == "标杆值"||full.DECC == "绩效值") {
                        return "——" ;
                    }
                    return formatNumber(full.CNT,0) ;
                }
            },
            {"data": "AvgFee","title":"次均费用(元)",
                "render": function(obj, type, full) {
                    if(full.AVGFEE==null||full.AVGFEE==""||full.AVGFEE==undefined){
                        return "——" ;
                    }else{
                        return formatNumber(full.AVGFEE,2) ;
                    }
                }
            },
            {"data": "AvgDays","title":"平均住院日",
                "render": function(obj, type, full) {
                    if(full.AVGDAYS==null||full.AVGDAYS==""||full.AVGDAYS==undefined){
                        return "——" ;
                    }else{
                        return formatNumber(full.AVGDAYS,2) ;
                    }
                }
            },
            {"data": "AvgDrugFee","title":"次均药品费(元)",
                "render": function(obj, type, full) {
                    if(full.AVGDRUG==null||full.AVGDRUG==""||full.AVGDRUG==undefined){
                        return "——" ;
                    }else{
                        return formatNumber(full.AVGDRUG,2) ;
                    }
                }
            },
            {"data": "DrugRatio","title":"药品费用占比(%)",
                "render": function(obj, type, full) {
                    if(full.AVGDRUGRATIO==null||full.AVGDRUGRATIO==""||full.AVGDRUGRATIO==undefined){
                        return "——" ;
                    }else{
                        return formatNumber(full.AVGDRUGRATIO,2) ;
                    }
                }
            },
            {"data": "AvgMateFee","title":"次均耗材费(元)",
                "render": function(obj, type, full) {
                    if(full.AVGMATER==null||full.AVGMATER==""||full.AVGMATER==undefined){
                        return "——" ;
                    }else{
                        return formatNumber(full.AVGMATER,2) ;
                    }
                }
            },
            {"data": "MaterialRatio","title":"耗材费占比(%)",
                "render": function(obj, type, full) {
                    if(full.AVGMATERRATIO==null||full.AVGMATERRATIO==""||full.AVGMATERRATIO==undefined){
                        return "——" ;
                    }else{
                        return formatNumber(full.AVGMATERRATIO,2) ;
                    }
                }
            },
            {"data": "MedFee","title":"次均医疗费(元)",
                "render": function(obj, type, full) {
                    if(full.DECC == "绩效值") {
                        return "——" ;
                    }else{
                        return formatNumber(full.MEDFEE,2);
                    }
                }
            },
            {"data": "NursFee","title":"次均护理费(元)",
                "render": function(obj, type, full) {
                    if(full.DECC == "绩效值") {
                        return "——" ;
                    }else{
                        return formatNumber(full.NURSFEE,2);
                    }
                }
            },
            {"data": "ManageFee","title":"次均管理费(元)",
                "render": function(obj, type, full) {
                    if(full.DECC == "绩效值") {
                        return "——" ;
                    }else{
                        return formatNumber(full.MANAGEFEE,2);
                    }
                }
            },
            {"data": "TechFee","title":"次均医技费(元)",
                "render": function(obj, type, full) {
                    if(full.DECC == "绩效值") {
                        return "——" ;
                    }else{
                        return formatNumber(full.TECHFEE,2);
                    }
                }
            },
            {"data": "DrugMaterFee","title":"次均药耗费(元)",
                "render": function(obj, type, full) {
                    if(full.DECC == "绩效值") {
                        return "——" ;
                    }else{
                        return formatNumber(full.DRUGMATERFEE,2);
                    }
                }
            }
        ];

        //填充数据
        var dataTab = [] ;
        for(var i = 0 ; i<4 ; i++) {
            var desc=data[i].DECC;
            if(desc=="本期值"){
                dataTab.push(data[i]) ;
                break; } }
        for(var i = 0 ; i<4 ; i++) {
            var desc=data[i].DECC;
            if(desc=="矫正值"){
                dataTab.push(data[i]) ;
                break; } }
        for(var i = 0 ; i<4 ; i++) {
            var desc=data[i].DECC;
            if(desc=="绩效值"){
                dataTab.push(data[i]) ;
                break; } }
        for(var i = 0 ; i<4 ; i++) {
            var desc=data[i].DECC;
            if(desc=="标杆值"){
                dataTab.push(data[i]) ;
                break; } }

        var paramsDataTables={searching:false,lengthChange:false,ordering:false,stateSave:true,info:false,paging:false,
            tableTitle:"排除特异病例后次均费用、费用构成及其对比情况表",columnDefs:[{"orderable": false,"targets": [ 0 ] }]};

        var depFeeOutAbnormalTable;
        if(compareType=="1"){
            depFeeOutAbnormalTable="clinicFeeOutAbnormalTable_A";
        }else{
            depFeeOutAbnormalTable="clinicFeeOutAbnormalTable_B";
        }
        var table = $("#"+tabId+" #"+depFeeOutAbnormalTable).dataTableBasic(columns,dataTab,paramsDataTables) ;

    });
}

//获取指标值
function getQuotaValue(quotaCode, callback ){
    var param = jQuery.extend(true,{},paramTabPage[tabId]);
    //json格式数据拷贝
    var paramNew= JSON.parse(JSON.stringify(param));
    paramNew.quotaCode=quotaCode;
    $.post(contextPath + "/DrgsIndexCal/indexCal.dhc", paramNew).done(function(data) {
        if(data.success){
            if(data.data.length>0){
                data = data.data;
                callback(data);
            }
        }
    });
}

//费用占比格式化
function feeRatio(data, quotaCode, cc){
    cc = cc || '';
    return (data[quotaCode]/100/data['TotalFee'+cc]).toFixed(0);
}
//病例分布表的病例数链接
//sliderValBenchLater 超标系数值,compareType:划分类型 1是标杆法区间划分 2是标差法区间划分
//compareObj 指标项(如平均住院日) ,abnomalType 区间类型  全部病例 all 未超标 not 超标N以内病例 in 超标N及以上病例 more
//dimensionType 维度类型（科室/主诊组）,dimensionCode 维度代码
function loadFeeDepCase(sliderValBenchLater,compareType,compareObj,abnomalType,dimensionType,dimensionCode){
    var param = jQuery.extend(true,{},paramTabPage[tabId]);
    var paramNew= JSON.parse(JSON.stringify(param));
    paramNew.type2=sliderValBenchLater;
    paramNew.compareType=compareType;
    paramNew.quotaCode=compareObj;
    paramNew.type3=abnomalType;
    var code='';
    var desc='';
    if(dimensionType=='dep'){ //科室维度页面 的科室维度
        code=paramNew.pardepCode;
        desc=paramNew.depDesc;
    }else if(dimensionType=="dep_clinic"){ //主诊组维度页面的病例明细
        code=paramNew.pargroupName;
        desc=dimensionCode;
        paramNew.monitorType='clinic';
        paramNew.pargroupName=code;
    }else{  //科室维度页面也 表格展开的主诊组维度
        var str = dimensionCode.split('||');
        code=str[1];
        desc=str[0];
        paramNew.monitorType='clinic';
        paramNew.dimensionCode=desc;
    }
    var destUrl = '/pages/yizheng/fenxi/feeAnalysisCase.jsp';//目标页面的url
    var destPageTitle = desc + '|病例明细';//目标页面的title
    var destPageId = code + 'clinicAnalysisCase';//目标页面的ID
    openTab(destUrl, destPageTitle,destPageId,destPageId,paramNew);
}

/**
 *
 * @ Discription：跳转病组分析
 */
function loadDRGPageSimple(desc, clinicCode,sliderValBenchLater,compareType,compareObj,abnomalType){
    var param = jQuery.extend(true,{},paramTabPage[tabId]);
    var paramNew= JSON.parse(JSON.stringify(param));
    paramNew.typeFour = '2'; //1表示从费用构成及对比点击进来的，2表示从区间分布点击进来的
    paramNew.type2=sliderValBenchLater;
    paramNew.compareType=compareType;
    paramNew.compareObj=compareObj;
    paramNew.type3=abnomalType;
    if (clinicCode) {
        param.pargroupName = clinicCode;
    } else {
        param.pargroupName = null;
    }
    var destUrl = '/pages/yizheng/fenxi/feeAnalysisDRGSimple.jsp';//目标页面的url
    var destPageTitle = desc + '|病组费用分类分析';//目标页面的title
    var destPageId = param.pardepCode + 'feeAnalysisDRG';//目标页面的ID
    openTab(destUrl, destPageTitle,destPageId,destPageId,paramNew);
}

/**
 * 费用构成
 * @param data
 */
function feeStrucClinic(data,stdData){

    var data = JSON.parse(data);
    var stdData = JSON.parse(stdData);

    $('#'+tabId+' #feeStrucModal').modal({
        keyboard: false
    })
    var tableData = [
        {ddesc:'医疗费用', value: data.MedFee, stdValue: stdData.MedFee},
        {ddesc:'护理费用', value: data.NursFee, stdValue: stdData.NursFee},
        {ddesc:'管理费用', value: data.ManageFee, stdValue: stdData.ManageFee},
        {ddesc:'医技费用', value: data.TechFee, stdValue: stdData.TechFee},
        {ddesc:'药品耗材费用', value: data.DrugMaterFee, stdValue: stdData.DrugMaterFee},
        {ddesc:'合计（次均费用）', ccode: 'all', value: data.AvgFee, stdValue: stdData.AvgFee}
    ];
    var paramsDataTables={searching:false,lengthChange:false,ordering:false,stateSave:true,info:false,paging:false,dom: '<"top">t<"bottom"><"clear">'};
    var columns = [
        {"data": "ddesc","title":"费用类别"},
        {"data": "value","title":"本期值",
            "render": function(obj, type, full) {
                if (full.value > full.stdValue){
                    return '<span class="text-danger" title="超标">'+full.value+'</span>';
                } else {
                    return '<span>'+full.value+'</span>';

                }
            }
        },
        {"data": "valueRatio","title":"本期值占比（%）",
            "render": function(obj, type, full) {
                return (full.value*100/tableData[5].value).toFixed(2);
            }
        },
        {"data": "stdValue","title":"标杆值"},
        {"data": "stdValueRatio","title":"标杆值占比（%）",
            "render": function(obj, type, full) {
                return (full.stdValue*100/tableData[5].stdValue).toFixed(2);
            }
        }
    ];


    //饼图
    var feeEchartData = tableData.filter(function (v) {return v.ccode!=='all'}).map(function(v){
        return {
            name : v.ddesc,
            value : v.value
        };
    });

    setTimeout(function(){
        pieCharts($('#'+tabId+' #feeStrucChart'),feeEchartData ,'费用构成图图', '');
        $('#'+tabId+' #feeStrucTable').dataTableBasic(columns,tableData,paramsDataTables) ;
    },400);
}